<template>
  <div>
    <pdf-view
      :query-id="queryId"
      :contractId="docId"
      :view-mode="viewMode"
      downName="放款通知书"
      :sig-no="sigNo"
    ></pdf-view>
    <!-- <el-button @click="deleteNotice"
               v-if="tableData.loan_notice_id">删除</el-button> -->
  </div>
</template>

<script>
import PdfView from '@/credit/views/county/unionProvince/components/PdfView'
export default {
  components: {
    PdfView,
  },
  props: {
    queryId: String,
    viewMode: {
      type: Boolean,
      default: true,
    },
  },
  data() {
    return {
      tableName: 'loan_notice',
      docId: '',
      sigNo: '',
      loading: false,
      params: {},
      tableData: {},
    }
  },
  watch: {
    queryId: {
      handler: function () {
        this.getData()
      },
      immediate: true,
    },
  },
  created() {},
  methods: {
    getData() {
      this.docId = ''
      this.sigNo = ''
      if (!this.queryId) {
        return
      }
      this.loading = true
      this.params['customer_related_id.eq'] = this.queryId
      this.$api
        .getData(this.$serviceName, this.tableName, this.params, { create_time: 'desc' })
        .then(res => {
          const data = res?.data?.[0] ?? {}
          this.tableData = data
          this.docId = data.doc_id || ''
          this.sigNo = data.sign_no || ''
        })
        .finally(() => {
          this.loading = false
        })
    },
    deleteNotice() {
      this.$api
        .deleteData(this.$serviceName, this.tableName, this.tableData.loan_notice_id)
        .then(() => this.getData())
    },
  },
}
</script>
<style lang="scss" scoped></style>
